<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
</head>
<body>
<div class="x-nav">
<span class="layui-breadcrumb">
        <a href="#">小程序管理</a>
        <a href="#">优秀教师事迹</a>
        <a href="#">添加事迹</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<form class="layui-form" action="" style="width: 30%;" onsubmit="return false">
    <br>
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" id="title" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <textarea id="demo" style="display: none;"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo" id="add">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
</html>
<script>
    layui.use('layedit', function(){
        layedit = layui.layedit;
        index   = layedit.build('demo',{
            tool: ['left', 'center', 'right']
        }); //建立编辑器
        layedit.getContent(index);
    });
</script>
<script>
    $("#add").click(function () {
        var content = layedit.getContent(index);
        var title   = $("#title").val();
        if(!content || !title){
            layer.alert('有未完善信息')
        }
        $.ajax({
            url:"{:url('/story/storyAdd')}",
            data:{title:title,content:content},
            type:"post",
            dataType:"json",
            success:function (res){
                if(res.code){
                    if (res.code){
                        layer.msg(res.msg, {icon: 1, time: 2000}, function () {
                            window.location.reload();
                        });
                        return;
                    } else {
                        layer.msg(res.msg, {icon: 5, time: 2000});
                        return;
                    }
                }
            }
        })

    })
</script>
